/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.expression;


import dex.compiler.model.base.Place;


/**
 * An array indexing expression such as <code>foo[x]</code>.
 *
 * <p>An array indexing expression is made of two subexpressions,
 * the array and the index.  In the above example, <code>foo</code>
 * is the array subexpression and <code>x</code> is the index
 * expression.
 * 
 * <p>To survive semantic analysis, the array subexpression (<code>foo</code>
 * in the above example) must resolve to an array type.  The index
 * subexpression (<code>x</code> in the above example) must resolve 
 * to the <code>uint32</code> type.
 * 
 * <p>The evaluated type of an array indexing expression is the 
 * element type of its array subexpression.
 */
public class ArrayExpression extends Expression {
	
	
	/**
	 * The expression that evaluates to the array whose values
	 * we're interested in.
	 */
	private Expression array;
	
	
	/**
	 * The index into the array of interest.
	 */
	private Expression index;

	
	/**
	 * Constructs a new ArrayExpression.
	 * 
	 * @param place  The place where this array expression originated
	 * @param array  The expression that evaluates to the array of interest
	 * @param index  The index in that array of the value to return
	 */
	public ArrayExpression(Place place, Expression array, Expression index) {
		super(place);
		if (array == null)  {
			throw new IllegalArgumentException();
		}
		if (index == null)  {
			throw new IllegalArgumentException();
		}
		this.array = array;
		this.index = index;
	}
	
	
	/**
	 * Returns the array subexpression.
	 * 
	 * @return  the array subexpression.
	 */
	public Expression getArray() {
		return array;
	}
	
	
	/**
	 * Returns the index subexpression.
	 * 
	 * @return the index subexpression
	 */
	public Expression getIndex() {
		return index;
	}

	
	@Override
	public String toString() {
		return array + "[" + index + "]";
	}

	
}
